﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace FeedAntGame.Support
{
    public class XL_XML
    {
        public static XmlElement Read_Root(String file_path)
        {
            XmlElement kq;
            XmlDocument Tai_lieu = new XmlDocument();
            Tai_lieu.Load(file_path);
            kq = (XmlElement)Tai_lieu.DocumentElement;
            return kq;
        }

        public static XmlElement Tao_Goc(String Ten)
        {
            XmlElement kq;
            XmlDocument Tai_lieu = new XmlDocument();
            kq = Tai_lieu.CreateElement(Ten);
            Tai_lieu.AppendChild(kq);
            return kq;
        }

        public static XmlElement Tao_Nut_Con(XmlElement Nut_Cha, String Ten_Nut_Con)
        {
            XmlElement kq;
            XmlDocument Tai_lieu = Nut_Cha.OwnerDocument;
            kq = Tai_lieu.CreateElement(Ten_Nut_Con);
            Nut_Cha.AppendChild(kq);
            return kq;
        }

        public static void Ghi_Nut(XmlElement Nut_Goc, String Ten_file)
        {
            XmlDocument Tai_lieu = Nut_Goc.OwnerDocument;
            Tai_lieu.Save(Ten_file);
        }

        public static int Lay_So_Nut_Con(XmlElement NutCha)
        {
            int kq = 0;
            foreach (XmlElement Nut_Con in NutCha.ChildNodes)
                kq++;
            return kq;
        }
    }
}